{include file="common/header" title="管理员增加"}
<script src="__COMMON__/lib/editor.md/editormd.min.js"></script>
<link rel="stylesheet" href="__COMMON__/lib/editor.md/css/editormd.min.css">
<style>
    .layui-form-switch {
        margin-top: 6px;
    }
</style>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-col-xs12">
            <blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 基本设置</blockquote>
            <div class="border">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md9 layui-col-xs7">
                        <div class="layui-form-item magt3">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="title" class="layui-input newsName" lay-verify="title"
                                       placeholder="请输入标题" required >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">摘要</label>
                            <div class="layui-input-block">
                                <textarea placeholder="请输入内容摘要" name="digest"
                                          class="layui-textarea abstract"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3 layui-col-xs5">
                        <div class="layui-upload-list thumbBox mag0 magt3">
                            <img class="layui-upload-img thumbImg">
                        </div>
                        <input type="hidden" name="pic" value="">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12">
            <blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> SEO</blockquote>
            <div class="border">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md9 layui-col-xs7">
                        <div class="layui-form-item magt3">
                            <label class="layui-form-label"> 关键词</label>
                            <div class="layui-input-block">
                                <input type="text" name="keywords" class="layui-input" lay-verify=""
                                       placeholder="关键词;多个以英文逗号“,”分隔">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"> 描述</label>
                            <div class="layui-input-block">
                                <textarea placeholder="请输入描述" name="description"
                                          class="layui-textarea abstract"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12">
            <blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 文章内容</blockquote>
            <div class="layui-input-block editormd" id="editor">
                <!-- 用于接受后台传递的数据 -->
                <textarea class="editormd-markdown-textarea" lay-verify="content" name="editor-markdown-doc"></textarea>
                 <textarea class="editormd-html-textarea" name="editor-html-code" ></textarea>
                <script>
                    var testEditor = editormd({
                        id: "editor",
                        width: "auto",
                        height: 700,
                        path: "__COMMON__/lib/editor.md/lib/",
                        // markdown : '',
                        placeholder: '欢迎使用Editor编辑器',
                        codeFold: true,
                        //syncScrolling : false,
                        saveHTMLToTextarea: true,    // 保存 HTML 到 Textarea
                        searchReplace: true,
                        // watch : false,                // 关闭实时预览
                        htmlDecode: "style,script,iframe|on*",            // 开启 HTML 标签解析，为了安全性，默认不开启
                        //toolbar  : false,             //关闭工具栏
                        emoji: true,
                        taskList: true,
                        tocm: true,
                        tex: true,                   // 开启科学公式TeX语言支持，默认关闭
                        flowChart: true,             // 开启流程图支持，默认关闭
                        sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
                        imageUpload: true,
                        imageFormats: ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
                        imageUploadURL: "{:url('upload')}",
                    });
                </script>
            </div>
        </div>
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md6 layui-col-xs12">
                <blockquote class="layui-elem-quote title"><i class="seraph icon-caidan"></i> 分 类</blockquote>
                <div class="border">
                    <div class="layui-form-item">
                        <label class="layui-form-label"> 所　属</label>
                        <div class="layui-input-block">
                            <select name="column_id" lay-verify="column_id" required >
                                <option value="">请选择栏目</option>
                                {volist name="columnList" id="item"}
                                {eq name="item.pid" value="0"}
                                <option value="{$item.id}">{$item.name}</option>
                                {else /}
                                <option value="{$item.id}">{:str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $item.level)}|---{$item.name}</option>
                                {/eq}
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item magt10">
                        <label class="layui-form-label"> 来　源</label>
                        <div class="layui-input-block">
                            <input type="text" name="source" class="layui-input" lay-verify=""
                                   placeholder="请输入来源" value="原创" >
                        </div>
                    </div>
                    <div class="layui-form-item magt10">
                        <label class="layui-form-label"> 发布者</label>
                        <div class="layui-input-block">
                            <input type="text" name="author" value="{:decrypt(session('username', '','admin'),config('assist_key'))}" class="layui-input" lay-verify="" placeholder="请输入作者">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 layui-col-xs12">
                <blockquote class="layui-elem-quote title"><i class="layui-icon">&#xe609;</i> 发 布</blockquote>
                <div class="border">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><i class="layui-icon">&#xe60e;</i> 状　态</label>
                        <div class="layui-input-block newsStatus">
                            <select name="status" lay-verify="required">
                                <option value="0">立即发布</option>
                                <option value="1">等待审核</option>
                                <option value="2">保存草稿</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md6 layui-col-xs12">
                        <label class="layui-form-label"><i class="layui-icon">&#xe609;</i> 发　布</label>
                        <div class="layui-input-block">
                            <input type="radio" name="create_time" title="立即发布" lay-skin="primary" lay-filter="release"
                                   checked/>
                            <input type="radio" name="create_time" title="定时发布" lay-skin="primary"
                                   lay-filter="release"/>
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide releaseDate">
                        <label class="layui-form-label"></label>
                        <div class="layui-input-block">
                            <input type="text" name="publish_time" class="layui-input" id="release" placeholder="请选择日期和时间" readonly />
                        </div>
                    </div>
                    <div class="layui-form-item openness">
                        <label class="layui-form-label"><i class="seraph icon-look"></i> 公开度</label>
                        <div class="layui-input-block">
                            <input type="radio" name="isopen" value="0" title="开放浏览" lay-skin="primary" checked/>
                            <input type="radio" name="isopen" value="1" title="私密浏览" lay-skin="primary"/>
                        </div>
                    </div>
                    <div class="layui-form-item newsTop">
                        <label class="layui-form-label"><i class="seraph icon-zhiding"></i> 置　顶</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="istop" value="1" lay-skin="switch" lay-text="是|否">
                        </div>
                    </div>
                    <hr class="layui-bg-gray"/>
                    <div class="layui-right">
                        <a class="layui-btn layui-btn-sm" lay-filter="save" lay-submit><i
                                class="layui-icon">&#xe609;</i>发布</a>
                        <a class="layui-btn layui-btn-primary layui-btn-sm" lay-filter="look" lay-submit>预览</a>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer', 'laydate', 'upload'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            upload = layui.upload,
            laydate = layui.laydate,
            $ = layui.jquery;

        //定时发布
        laydate.render({
            elem: '#release',
            type: 'datetime',
            trigger : "click",
        });
        form.on("radio(release)",function(data){
            if(data.elem.title == "定时发布"){
                $(".releaseDate").removeClass("layui-hide");
                $(".releaseDate #release").attr("lay-verify","required");
            }else{
                $(".releaseDate").addClass("layui-hide");
                $(".releaseDate #release").removeAttr("lay-verify");
                $(".releaseDate #release").val('');
            }
        });
        //执行实例
        var uploadInst = upload.render({
            elem: '.thumbBox' //绑定元素
            ,url: '{:url("upload")}' //上传接口
            ,field: 'editormd-image-file'
            ,accept: 'images'
            ,drag: false
            ,data: {
                old: function(){
                    return $('input[name="pic"]').val();
                }
            }
            , method: "post",
            done: function (res, index, upload) {
                $('.thumbImg').attr('src', res['url']);
                $('input[name="pic"]').val(res['url']);
                $('.thumbBox').css("background", "#fff");
            }
            , error: function () {
                layer.msg('缩略图上传失败!');
            }
        });

        //自定义验证规则
        form.verify({
            title: function (val) {
                if (val === '') {
                    return "文章标题不能为空";
                }
            },
            content: function (val) {
                if (val === "") {
                    return "内容不能为空";
                }
            },
            column_id: function (val) {
                if (val === "") {
                    return "必须选择所属栏目";
                }
            },
            time: function (val) {
                if (val === "") {
                    return "定时发布时间不能为空";
                }
            }
        });

        //预览
        form.on("submit(look)", function () {
            layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问");
            return false;
        });

        //监听提交
        form.on('submit(save)', function (data) {

            //发异步，把数据提交给php
            $.post('{:url("save")}', {data: data.field}, function (reg) {
                switch (reg.code) {
                    case 0:
                        layer.msg(reg.msg, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            // 可以对父窗口进行刷新
                            x_admin_father_reload();
                        });
                        break;
                    default:
                        layer.msg(reg.msg, {icon: 5});
                }

            }, 'json');
            return false;
        });


    });
</script>
</body>

</html>